from django.shortcuts import render
from django.http.response import HttpResponse
import datetime
from firepark_admin.models import register, use_records, park_info, parking_lot
from firepark_park.park import *


# 进入停车场之前
def will_in_park(request):
    if request.method == "GET":
        park_id = request.GET.get("park_id")
    elif request.method == "POST":
        park_id = request.POST.get("park_id")
    is_available = parking_lot_available(park_id)
    result = "未满" if is_available else "已满"
    return HttpResponse(result)


# 进入停车场后
def doing_in_park(request):
    if request.method == "GET":
        park_id = request.GET.get("park_id")
        plate_number = request.GET.get("plate_number")
    elif request.method == "POST":
        park_id = request.POST.get("park_id")
        plate_number = request.POST.get("plate_number")
    in_park(park_id, plate_number)
    return HttpResponse('doing_in_park')

#进入车位触发
def parking_lot_trigger_in(request):
    if request.method == "GET":
        park_id = request.GET.get("park_id")
        lot_id = request.GET.get("lot_id")
    elif request.method == "POST":
        park_id = request.POST.get("park_id")
        lot_id = request.POST.get("lot_id")
    parking_lot_update(park_id, lot_id, False)
    return HttpResponse("parking_lot_trigger_in")


#离开车位触发
def parking_lot_trigger_out(request):
    if request.method == "GET":
        park_id = request.GET.get("park_id")
        lot_id = request.GET.get("lot_id")
    elif request.method == "POST":
        park_id = request.POST.get("park_id")
        lot_id = request.POST.get("lot_id")
    parking_lot_update(park_id, lot_id, True)
    return HttpResponse("parking_lot_trigger_out")


#出停车场
def will_out_park(request):
    if request.method == "GET":
        park_id = request.GET.get("park_id")
        plate_number = request.GET.get("plate_number")
    elif request.method == "POST":
        park_id = request.POST.get("park_id")
        plate_number = request.POST.get("plate_number")
    fee = out_park(park_id, plate_number)
    return HttpResponse(str(fee))